/* ******************************************************************
 * This file is part of the escal project and distributed under the
 * terms of the GNU General Public License Version 3
 * Copyright (C) 2008 Epocher (xijiaosdq@gmail.com)
 * See COPYING file for licensing information.
 *******************************************************************/

#ifndef CURL_LINK_MANAGER_H
#define CURL_LINK_MANAGER_H
#include "link_manager.h"
#include "curl/curl.h"
#include "curl/types.h"

class CurlLinkManager:public BaseLinkManager{
	Q_OBJECT
public:
	CurlLinkManager(FileManager *fileManager, const QUrl &url,
			QObject *parent=0);
	~CurlLinkManager();
	void stop();
	static size_t CurlWriteFunc(void *buffer, size_t size, 
			size_t nmemb, void *stream);
	static int CurlDebugFunc(CURL *, curl_infotype, char *, size_t,
			void *);
	void cleanUp();
protected:
	int writeToFileManager(char *buffer,size_t size);
	void writeDebugInfo(char *buffer,size_t size);
	void run();
private:
	FileManager *fileManager;
	CURL *curl;
	QByteArray urlByteArray;
	CURLcode curl_res;
	QUrl url;
	int pieceIndex;
	bool gotInfo;
	qint64 offset;
	int status;
	int retry;
	bool reconnect;
	bool quit;
	bool gotPiece;

};


#endif /* CURL_LINK_MANAGER_H */
